package com.kudian.restful.service;

import com.kudian.common.persistence.HibernateDao;
import com.kudian.common.service.BaseService;
import com.kudian.common.utils.StringUtils;
import com.kudian.restful.dao.AdDao;
import com.kudian.restful.dao.LayoutDao;
import com.kudian.restful.dao.RegionDao;
import com.kudian.restful.entity.Ad;
import com.kudian.restful.entity.Layout;
import com.kudian.restful.entity.Region;
import com.kudian.restful.vo.ad.AdItemVO;
import com.kudian.restful.vo.ad.MidAdRetVO;
import com.kudian.restful.vo.ad.MidAdVO;
import com.kudian.restful.vo.region.RegionItemVO;
import org.apache.log4j.Logger;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/4/18.
 */
@Service
@Transactional(readOnly = true)
public class RegionService extends BaseService<Region, Integer> {
    private static final Logger logger = Logger.getLogger(RegionService.class);

    @Autowired
    private RegionDao regionDao;

    @Override
    public HibernateDao<Region, Integer> getEntityDao() {
        return regionDao;
    }

    public List<RegionItemVO> queryRegions(Integer parentId) {
        List<RegionItemVO> ret = new ArrayList<RegionItemVO>();
        List<Region> ls = getEntityDao().find(Restrictions.eq("parentId", parentId));
        for (Region r : ls) {
            RegionItemVO item = new RegionItemVO();
            item.setId(r.getId());
            item.setName(r.getName());
            ret.add(item);
        }
        return ret;
    }
}
